<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html>
<html>
<head>
<title>科目设置</title>
<jsp:include page="../inc.jsp"></jsp:include>
</head>
<body>	
	<script type="text/javascript">
		var dataGrid;
		$(function() {
			dataGrid = $('#dataGrid').datagrid({
				url : '${pageContext.request.contextPath}/business/accounting/kMSZJBSJ/dataGrid.shtml',
				fit : true,
				border : false,
				pagination : true,
				idField : 'id',
				pageSize : 20,
				pageList : [ 10, 20, 30, 40, 50 ],
				checkOnSelect : false,
				selectOnCheck : false,
				nowrap : false,
				striped : true,
				rownumbers : true,
				singleSelect : true,
				frozenColumns:[[
				        		{
					field : 'ID',
					title : '编号',
					width : 150,
					hidden : true
				},{
					field : 'action',
					title : '操作',
					width : 430,
					align:'center',
					formatter : function(value, row, index) {
						var str = '';
							str += $.formatString('<a onclick="editFun(\'{0}\',\'{1}\');" src="{2}" >编辑</a>', row.ID,row,row.ZT);
						str += '&nbsp;&nbsp;';
							str += $.formatString('<a onclick="deleteFun(\'{0}\',\'{1}\',\'{2}\');" src="{3}" >删除</a>', row.ID,row.KMSZID,row.ZT);
						str += '&nbsp;&nbsp;';
						    str += $.formatString('<a  onClick="spFun(\'{0}\') ">新增经办</a>',row.ID);
			            str += '&nbsp;&nbsp;';
					    str += $.formatString('<a onClick="SQJY(\'{0}\');" >申请禁用</a>',row.ID);
			            str += '&nbsp;&nbsp;';
			            	str += $.formatString('<a  onClick="jinyongJB(\'{0}\') ">禁用经办审批</a>',row.ID);
			            str += '&nbsp;&nbsp;';
					        str += $.formatString('<a  onClick="jinyongJB(\'{0}\') ">重审禁用</a>',row.ID);
			            str += '&nbsp;&nbsp;';
				            str += $.formatString('<a  onClick="jinyongQX(\'{0}\') ">禁用操作取消</a>',row.ID);
						return str;
					}
				}
				        	]],
				columns : [ [{
					field : 'ZT',
					title : '数据状态',
					width : 150,
					sortable : true,
	                formatter: function(value,row,index){
	                  	                             	 if(value == '1'){
	                  	                  					return '新增审批中';
	                  	                  				 }
	                  	                             	 else if(value == '2'){
	                  	                  					return '正在使用中';
	                  	                  				 }
	                  	                             	 else if(value == '3'){
	                  	                  					return '停用审批中';
	                  	                  				 }
	                  	                             	 else if(value == '4'){
	                  	                             		return '禁用中';
	                  	                             	 }else if(value == '5'){
	                  	                             		return '修改审批中';
	                  	                             	 }
	                  	                 			}
				},{
					field : 'SPZT',
					title : '审批状态',
					width : 150,
					sortable : true,
	                formatter: function(value,row,index){
	                  	                             	 if(value == '1'){
	                  	                  					return '待审批';
	                  	                  				 }
	                  	                             	 else if(value == '2'){
	                  	                  					return '初审通过';
	                  	                  				 }
	                  	                             	 else if(value == '3'){
	                  	                  					return '初审不通过';
	                  	                  				 }
	                  	                 			}
				},{
					field : 'HSDW',
					title : '核算单位',
					width : 150,
					sortable : true
				},{
					field : 'JBJG',
					title : '经办机构',
					width : 150,
					sortable : true
				},{
					field : 'ZTDM',
					title : '账套代码',
					width : 150,
					sortable : true
				} ,{
					field : 'KMBH',
					title : '科目编号',
					width : 150,
					sortable : true
				}, {
					field : 'KMMC',
					title : '科目名称',
					width : 150,
					sortable : true
				}, {
					field : 'KMJB',
					title : '科目级别',
					width : 150,
					sortable : true
				}
				, {
					field : 'KMSX',
					title : '科目属性',
					width : 150,
					sortable : true
				}
				, {
					field : 'KJKMLB',
					title : '会计科目类别',
					width : 150,
					sortable : true,
					hidden : true
				}
				, {
					field : 'KMYEFX',
					title : '余额方向',
					width : 150,
					sortable : true
				}
				, {
					field : 'SFMJKM',
					title : '是否末级科目',
					width : 150,
					sortable : true
				}, {
					field : 'NCYE',
					title : '年初余额',
					width : 150,
					sortable : true
				}
				, {
					field : 'YE',
					title : '余额',
					width : 150,
					sortable : true
				}
				, {
					field : 'BNLJJF',
					title : '本年累计借方',
					width : 150,
					sortable : true
				}
				, {
					field : 'BNLJDF',
					title : '本年累计贷方',
					width : 150,
					sortable : true
				}
				, {
					field : 'TZBJ',
					title : '台账标记',
					width : 150,
					sortable : true
				}
				, {
					field : 'RJZLX',
					title : '日记账类型',
					width : 150,
					sortable : true
				},{
					field : 'FZHSLX',
					title : '辅助核算类型',
					width : 150,
					sortable : true
				},{
					field : 'CRSJ',
					title : '插入时间',
					width : 150,
					sortable : true
				},{
					field : 'CRSJ',
					title : '创建时间',
					width : 150,
					sortable : true
				}
				, {
					field : 'KJND',
					title : '会计年度',
					width : 150,
					sortable : true
				}
				, {
					field : 'PKMBH',
					title : '父科目',
					width : 150,
					sortable : true,
					hidden : true
				},
				{
					field : 'CZY',
					title : '操作员',
					width : 150,
					sortable : true,
					hidden : true
				},
				{
					field : 'KMSZID',
					title : '科目设置ID',
					width : 150,
					sortable : true,
					hidden : false
				}
				]],
				toolbar : '#toolbar',
				onLoadSuccess : function() {
					$('#searchForm table').show();
					parent.$.messager.progress('close');
					$(this).datagrid('tooltip');
				}
			});
		});
	
		function deleteFun(id,kmszid,zt) {
			alert(zt);
			if(zt==1||zt==3){
				
			
			if (id == undefined) {
				var rows = dataGrid.datagrid('getSelections');
				id = rows[0].ID;
			}
			parent.$.messager.confirm('询问', '您是否要删除当前选择数据？', function(b) {
				if (b) {
					parent.$.messager.progress({
						title : '提示',
						text : '数据处理中，请稍后....'
					});
					$.post('${pageContext.request.contextPath}/business/accounting/kMSZJBSJ/delete.shtml?ID='+id+'&KMSZID='+kmszid,
				    {
						id : id
					}, function(result) {
						if (result.success) {
							parent.$.messager.alert('提示', result.msg, 'info');
							dataGrid.datagrid('reload');
						}
						parent.$.messager.progress('close');
					}, 'JSON');
				}
			});
		}
		
		else
			{
			alert("不允许删除！");
			}
		}
		function editFun(id) {
			if (id == undefined) {
				var rows = dataGrid.datagrid('getSelections');
				id = rows[0].ID;
			}
			parent.$.modalDialog({
				title : '编辑科目',
				width : 780,
				height : 500,
				href : '${pageContext.request.contextPath}/business/accounting/kMSZJBSJ/editPage.shtml?id='+id,
				buttons : [ {
					text : '保存',
					handler : function() {
						parent.$.modalDialog.openner_dataGrid = dataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
						var f = parent.$.modalDialog.handler.find('#form');
						f.submit();
					}
				} ]
			});
		}
		
	
		function addFun() {
			var rows = dataGrid.datagrid('getSelections');
			var id= 0;
			if(rows.length ==1){
				id = rows[0].ID;
			} 
			parent.$.modalDialog({
				title : '新增科目',
				width : 780,
				height : 500,
				href : '${pageContext.request.contextPath}/business/accounting/kMSZJBSJ/addPage.shtml?kmid='+id,
				buttons : [ {
					text : '添加',
					handler : function() {
						parent.$.modalDialog.openner_dataGrid = dataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
						var f = parent.$.modalDialog.handler.find('#form');
						f.submit();
					}
				} ]
			});
		}
		/*  新增审批  */
		function spFun(id) {
			parent.$.modalDialog({
				title : '审批科目',
				width : 780,
				height : 500,
				href : '${pageContext.request.contextPath}/business/accounting/kMSZJBSJ/spPage.shtml?id='+id,
				buttons : [ {
					text : '通过',
					handler : function() {
						parent.$.modalDialog.openner_dataGrid = dataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
						var f = parent.$.modalDialog.handler.find('#form');
						 $("#TG").val("通过");
						f.submit();
					}
				},
				{
					text : '不通过',
					handler : function() {
						parent.$.modalDialog.openner_dataGrid = dataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
						var f = parent.$.modalDialog.handler.find('#form');
						$("#TG").val("不通过");
						f.submit();
					}
				}]
			});
		}
		/*  申请禁用  */
		function SQJY(id) {
			$.ajax({
				  type: 'POST',
				  url: '${pageContext.request.contextPath}/business/accounting/kMSZJBSJ/jySQ.shtml?id='+id,
				  success: function(data, textStatus, jqXHR){  
						dataGrid.datagrid('reload');
						if(data.zt==0){
							$.messager.confirm('提示:','禁用申请已提交,请无重复提交！');
						}else{
						$.messager.confirm('提示:','禁用申请已提交,等待审核！');
						}
				  },
				  dataType: 'json'
				});
		}
		/*  取消禁用  */
		function jinyongQX(id) {
			$.ajax({
				  type: 'POST',
				  url: '${pageContext.request.contextPath}/business/accounting/kMSZJBSJ/jinyongQX.shtml?id='+id,
				  success: function(data, textStatus, jqXHR){  
						dataGrid.datagrid('reload');
						$.messager.confirm('提示:','请确认是否取消禁用?',function(r){
						});
				  },
				  dataType: 'json',
				});
		}
		/*  禁用经办页面+重新审核页面  */
		function jinyongJB(id) {
			parent.$.modalDialog({
				title : '禁用经办审批',
				width : 780,
				height : 500,
				href : '${pageContext.request.contextPath}/business/accounting/kMSZJBSJ/jyPage.shtml?id='+id,
				buttons : [ {
					text : '通过',
					handler : function() {
						parent.$.modalDialog.openner_dataGrid = dataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
						var f = parent.$.modalDialog.handler.find('#form');
						 $("#TG").val("通过");
						$.messager.confirm('提示:','审核通过,已禁用！',function(r){
						f.submit();
						});
					}
				},
				{
					text : '不通过',
					handler : function() {
						parent.$.modalDialog.openner_dataGrid = dataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
						var f = parent.$.modalDialog.handler.find('#form');
						$("#TG").val("不通过");
						f.submit();
						$.messager.confirm('提示:','审核不通过,请重审！',function(r){
						});
					}
				}]
			});
		}
		/* 历史数据 */
		function lssjFun() {
			var rows = dataGrid.datagrid('getSelections');
			var id= 0;
			if(rows.length ==1){
				id = rows[0].ID;
			} 
			parent.$.modalDialog({
				title : '历史数据',
				width : 780,
				height : 500,
				href : '${pageContext.request.contextPath}/business/accounting/kMSZJBSJ/kmszlssj.shtml?id='+id,
			});
		}
		
		
		/* 审批历史 */
		function splx() {
			var rows = dataGrid.datagrid('getSelections');
			var id= 0;
			if(rows.length ==1){
				id = rows[0].ID;
			} 
			parent.$.modalDialog({
				title : '历史数据',
				width : 780,
				height : 500,
				href : '${pageContext.request.contextPath}/business/accounting/kMSZJBSJ/kMSZLSSJspls.shtml?id='+id,
			});
		}
		function searchFun() {
			dataGrid.datagrid('load', $.serializeObject($('#searchForm')));
		}
		function cleanFun() {
			$('#searchForm input').val('');
			dataGrid.datagrid('load', {});
		}
		
		$('#kjnd').combobox({
			url:'${pageContext.request.contextPath}/business/accounting/combobox/KjndSel.shtml',
		    valueField:'STANDARD_CODE',
		    textField:'TITLE'
		});
		
		$('#kmsx').combobox({
			url:'${pageContext.request.contextPath}/business/accounting/combobox/KmsxSel.shtml',
		    valueField:'STANDARD_CODE',
		    textField:'TITLE'
		});
		
		$('#tzbj').combobox({
			url:'${pageContext.request.contextPath}/business/accounting/combobox/TzbjSel.shtml',
		    valueField:'STANDARD_CODE',
		    textField:'TITLE'
		});
		
		$('#rjzlx').combobox({
			url:'${pageContext.request.contextPath}/business/accounting/combobox/RjzlxSel.shtml',
		    valueField:'STANDARD_CODE',
		    textField:'TITLE'
		});
	</script>
	<div class="easyui-layout" data-options="fit : true,border : false">
		<div data-options="region:'north',title:'',border:false" style=" overflow: hidden;" >
			<form id="searchForm">
				<table class="form_view_border" bordercolordark="#FFFFFF" bordercolorlight="#45b97c" border="px" cellpadding="0" cellspacing="0" style="">
					<tr>
						<th class="panel-header"><nobr>会计年度</nobr></th>
						<td style="width: 150px">               
                                <input class="easyui-combobox" id="kjnd" name = "KJND_EQ_STR" style="width: 150px;height: 27px;" 
                                data-options="valueField:'STANDARD_CODE', textField:'TITLE', panelHeight:'auto'" >  
                            </td>
						<th class="panel-header"><nobr>科目属性</nobr></th>
						<td style="width: 150px">               
                                <input class="easyui-combobox" id="kmsx" name = "KMSX_EQ_STR" style="width: 150px;height: 27px;" 
                                data-options="valueField:'STANDARD_CODE', textField:'TITLE', panelHeight:'auto'" >  
                            </td>
						<th class="panel-header"><nobr>会计科目</nobr></th>
						<td>
							<input style="width: 150px;height: 27px;" class="easyui-text"
							name="KMBH_EQ_STR" 
							placeholder="会计科目" 
							class="span2" />
						</td>
						<th class="panel-header"><nobr>台账标记</nobr></th>
						<td style="width: 150px">               
                                <input class="easyui-combobox" id="tzbj" name = "TZBJ_EQ_STR" style="width: 150px;height: 27px;" 
                                data-options="valueField:'STANDARD_CODE', textField:'TITLE', panelHeight:'auto'" >  
                            </td>
						<th class="panel-header"><nobr>日记账类型</nobr></th>
						<td style="width: 150px">               
                                <input class="easyui-combobox" id="rjzlx" name = "RJZLX_EQ_STR" style="width: 150px;height: 27px;" 
                                data-options="valueField:'STANDARD_CODE', textField:'TITLE', panelHeight:'auto'" >  
                            </td>
					</tr>
				</table>
			</form>
		</div>
		<div data-options="region:'center',border:false">
			<table id="dataGrid"></table>
		</div>
	</div>
	<div id="toolbar" style="display: none;">
		    <a href="javascript:void(0);" class="easyui-linkbutton" plain="true" iconCls="icon-search" onclick="searchFun();">查询</a>
			<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'brick_add',plain:true" onclick="addFun();">增加</a>
			<a href="javascript:void(0);" class="easyui-linkbutton" plain="true" iconCls="icon-edit" onclick="editFun();">修改</a>
			<a href="javascript:void(0);" class="easyui-linkbutton" plain="true" iconCls="icon-cancel" onclick="deleteFun();">删除</a>
		    <a href="javascript:void(0);" class="easyui-linkbutton" plain="true" iconCls="icon-reload" onclick="cleanFun();">重置</a>
<!-- 			<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'brick_delete',plain:true" onclick="hebin();">合并</a>
		    <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'brick_delete',plain:true" onclick="chaif();">拆分</a> -->
		    <a href="javascript:void(0);" class="easyui-linkbutton" plain="true" iconCls="icon-search" onclick="splx();">审批历史</a>
		    <a href="javascript:void(0);" class="easyui-linkbutton" plain="true" iconCls="icon-search" onclick="lssjFun();">历史数据</a>
	
	</div>
	
</body>
</html>